﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class ThuocXuatDAL:KetNoiDAL
    {
       public DataTable SelectAll_ThuocXuat()
       {
           SqlCommand cmd = new SqlCommand("SelectALL_ThuocXuat", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;

       }
       public DataTable SelectID_ThuocXuat(int MaPhieu)
       {
           SqlCommand cmd = new SqlCommand("SelectID_ThuocXuat", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDCT", MaPhieu);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertThuocXuat(int IDBN, string IDToa,int IDThuoc, string TenThuoc, string Dvt, string SL_Sang, string Sl_Trua, string SL_Toi, decimal SL1Ngay, int SoNgayUong, int Tong_SL, int SL_X, int GiaBan, int ThanhTien, string DuongDung, string IDPN, DateTime NgaySX, DateTime HanSD, string GhiChu)
       {
           
               SqlCommand cmd = new SqlCommand("Insert_ThuocXuat", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDBN", IDBN);
               cmd.Parameters.AddWithValue("@IDToa", IDToa);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@TenThuoc", TenThuoc);
               cmd.Parameters.AddWithValue("@Dvt", Dvt);
               cmd.Parameters.AddWithValue("SL_Sang", SL_Sang);
               cmd.Parameters.AddWithValue("@SL_Trua", Sl_Trua);
               cmd.Parameters.AddWithValue("@SL_Toi", SL_Toi);
               cmd.Parameters.AddWithValue("SL1Ngay", SL1Ngay);
               cmd.Parameters.AddWithValue("SoNgayUong", SoNgayUong);
               cmd.Parameters.AddWithValue("@Tong_SL", Tong_SL);
               cmd.Parameters.AddWithValue("@SL_X", SL_X);
               cmd.Parameters.AddWithValue("@GiaBan", GiaBan);
               cmd.Parameters.AddWithValue("@ThanhTien", ThanhTien);
               cmd.Parameters.AddWithValue("@DuongDung", DuongDung);
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("NgaySX", NgaySX);
               cmd.Parameters.AddWithValue("@HanSD", HanSD);
               cmd.Parameters.AddWithValue("@GhiChu", GhiChu);
              return cmd.ExecuteNonQuery();
           
       }
       public int UpdateThuocXuat(int IDCT,int IDBN, string IDToa,int IDThuoc, string TenThuoc, string Dvt, string SL_Sang, string Sl_Trua, string SL_Toi, decimal SL1Ngay, int SoNgayUong, int Tong_SL, int SL_X, int GiaBan, int ThanhTien, string DuongDung, string IDPN, DateTime NgaySX, DateTime HanSD, string GhiChu)
       {
          
               SqlCommand cmd = new SqlCommand("Update_ThuocXuat", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDCT", IDCT);
               cmd.Parameters.AddWithValue("@IDBN", IDBN);
               cmd.Parameters.AddWithValue("@IDToa", IDToa);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@TenThuoc", TenThuoc);
               cmd.Parameters.AddWithValue("@Dvt", Dvt);
               cmd.Parameters.AddWithValue("SL_Sang", SL_Sang);
               cmd.Parameters.AddWithValue("@SL_Trua", Sl_Trua);
               cmd.Parameters.AddWithValue("@SL_Toi", SL_Toi);
               cmd.Parameters.AddWithValue("SL1Ngay", SL1Ngay);
               cmd.Parameters.AddWithValue("SoNgayUong", SoNgayUong);
               cmd.Parameters.AddWithValue("@Tong_SL", Tong_SL);
               cmd.Parameters.AddWithValue("@SL_X", SL_X);
               cmd.Parameters.AddWithValue("@GiaBan", GiaBan);
               cmd.Parameters.AddWithValue("@ThanhTien", ThanhTien);
               cmd.Parameters.AddWithValue("@DuongDung", DuongDung);
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("NgaySX", NgaySX);
               cmd.Parameters.AddWithValue("@HanSD", HanSD);
               cmd.Parameters.AddWithValue("@GhiChu", GhiChu);
             return  cmd.ExecuteNonQuery();
          
       }
        public int Delete_ThuocXuat(int MaPhieu)
       {
           
               SqlCommand cmd = new SqlCommand("SelectID_ThuocXuat", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDCT", MaPhieu);
              return cmd.ExecuteNonQuery();
          
       }
    }
}
